home *** CD-ROM | disk | FTP | other *** search
- Path: admaix.sunydutchess.edu!ub!newserve!rebecca!rpi!not-for-mail
- From: shappir@libra.math.tau.ac.il (Shappir Dan)
- Newsgroups: comp.lang.c++,comp.lang.c++.moderated
- Subject: Re: Enumerated type converted to pointer? Legal?
- Followup-To: comp.lang.c++,comp.lang.c++.moderated
- Date: 13 Mar 1996 17:19:58 -0000
- Organization: School of Math & CS - Tel Aviv University , Tel Aviv , ISRAEL.
- Sender: cppmods@netlab.cs.rpi.edu
- Approved: devitto@ferndown.ate.slb.com
- Message-ID: <4i703u$1gl@netlab.cs.rpi.edu>
- References: <4hobji$mco@netlab.cs.rpi.edu>
- NNTP-Posting-Host: netlab.cs.rpi.edu
- X-Original-Date: 13 Mar 1996 09:21:33 GMT
-
- { comp.std.c++ removed from followups. -mod}
-
- Brad Stowers (bstowers@pobox.com) wrote:
-
- : Compile and run the above program. Is it just me, or should the last line
- : of the main() function ( FooBar(x, mdType1); ) have caused a type mismatch
- : error? I think I know why it didn't: mdType1 evaluates to an integer with
- : a value of 0, which is a valid value to pass as a pointer. In support of
- : this theory, the line:
-
- This is due to one of the differences between C and C++. In C the NULL
- pointer is defined as ((void*)0) while in C++ it's simply 0. This can raise
- all sorts of type conversion problems, for example:
-
- void foo(int bar) { ... }
- void foo(void* bar) { ... }
-
- ...
- foo(0);
- ...
-
- The compiler will not be able to determine which version of foo to call.
-
- Another type issue raised here is the implicit conversion between enums and
- integers. Like all implicit conversion this is useful but can also be
- annoying. Can anyone present a method for defining an enum or and enum-like
- type that cannot be implicitly converted to int ?
-
- Dan Shappir
- shappir@math.tau.ac.il
-
-
- [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
- [ Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm ]
- [ Moderation policy: http://www.connobj.com/cpp/guide.htm ]
- [ Comments? mailto:c++-request@netlab.cs.rpi.edu ]
-